/*
 * LEDStripController.h
 *
 *  Created on: Dec 11, 2011
 *      Author: steffen
 */

#ifndef LEDSTRIPCONTROLLER_H_
#define LEDSTRIPCONTROLLER_H_

#include <SPI.h>
#include <LPD8806.h>

class LEDStripController {

public:

	LEDStripController(LPD8806& ledStrip);
	// virtual ~LEDStripController(void) {}

	// API

	enum SwitchType
	{
		ST_START = 0x0,
		ST_PLAIN = ST_START,
		ST_FADE,
		ST_COUNT
	};

	void Switch(SwitchType switchType = ST_PLAIN);

	bool Dim(bool brighter);

private:

	static const byte mMaxBrightness = 0x7F;

	LPD8806& mLEDStrip;

	byte mBrightness;

	float mRedMultiplier;
	float mGreenMultiplier;
	float mBlueMultiplier;

	bool mEnabled;

	unsigned long mDimUpdateIntervalMs;
	unsigned long mFadeUpdateIntervalMs;

	unsigned long mDelayCounter;

	void Update(void);
	void Update(byte red, byte green, byte blue);

	void SwitchPlain(void);
	void SwitchFade(void);

	// Dimming of the LED strips
	//
	// Returns 'true' if dimming was successful, i.e.
	// there was at least one more step for dimming
	// left, otherwise 'false'
	bool Dim(
			bool brighter,				// Increases brightness if 'true', otherwise decreases
			unsigned long intervalMs,	// Interval between a change (increment/decrement) in brightness
			byte &brightness);

	bool DelayExpired(unsigned long delay);
};

#endif /* LEDSTRIPCONTROLLER_H_ */
